<%--
  Created by IntelliJ IDEA.
  User:
  Date: 2020/2/9
  Time: 8:29
  To change this template use File | Settings | File Templates.
--%>
<%@ page language="java" contentType="text/html; charset=utf-8" isELIgnored="false" pageEncoding="utf-8"%>
<%@ include file="/webpage/common/include/taglib.jsp"%>
<html>
<head>
    <meta charset="utf-8">
    <meta name="renderer" content="webkit|ie-comp|ie-stand">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width,initial-scale=1,minimum-scale=1.0,maximum-scale=1.0,user-scalable=no" />
    <meta http-equiv="Cache-Control" content="no-siteapp" />
    <!--[if lt IE 9]>
    <%@ include file="/webpage/common/include/ltie9.jsp"%>
    <!--<script type="text/javascript" src="/resources/lib/html5shiv.js"></script>-->
    <!--<script type="text/javascript" src="/resources/lib/respond.min.js"></script>-->
    <![endif]-->
    <%--<link rel="stylesheet" type="text/css" href="static/h-ui/css/H-ui.min.css" />--%>
    <link rel="stylesheet" type="text/css" href="${ctxStatic}/h-ui.admin/css/H-ui.admin.css" />
    <%--<link rel="stylesheet" type="text/css" href="lib/Hui-iconfont/1.0.8/iconfont.css" />--%>
    <link rel="stylesheet" type="text/css" href="${ctxStatic}/h-ui.admin/skin/default/skin.css" id="skin" />
    <%--<link rel="stylesheet" type="text/css" href="static/h-ui.admin/css/style.css" />--%>
    <%@include file="/webpage/common/include/head.jsp"%>
    <!--[if IE 6]>
    <%@ include file="/webpage/common/include/ltie6.jsp"%>
    <!--<script type="text/javascript" src="/resources/lib/DD_belatedPNG_0.0.8a-min.js" ></script>-->
    <!--<script>DD_belatedPNG.fix('*');</script>-->
    <![endif]-->
    <title>权限管理</title>
</head>
<body>
<input type="hidden" id="pageId" value="${pageId}"/>
<c:forEach items="${menus}" var="menu">
    <c:if test="${pageId==menu.menuId}">
        <c:if test="${menu.add == 1}">
            <input type="hidden" id="pageAdd" value="${menu.add}"/>
        </c:if>
        <c:if test="${menu.del == 1}">
            <input type="hidden" id="pageDel" value="${menu.del}"/>
        </c:if>
        <c:if test="${menu.upd == 1}">
            <input type="hidden" id="pageUpd" value="${menu.upd}"/>
        </c:if>
        <c:if test="${menu.look == 1}">
            <input type="hidden" id="pageLook" value="${menu.look}"/>
        </c:if>
    </c:if>
</c:forEach>

<nav class="breadcrumb"><i class="Hui-iconfont">&#xe67f;</i> 首页 <span class="c-gray en">&gt;</span> 管理员管理 <span class="c-gray en">&gt;</span> 权限管理 <a class="btn btn-success radius r" style="line-height:1.6em;margin-top:3px" href="javascript:location.replace(location.href);" title="刷新" ><i class="Hui-iconfont">&#xe68f;</i></a></nav>
<div class="page-container">
    <div class="text-c">
        <div class="Huiform"  target="_self">
            <input type="text" class="input-text" style="width:250px" placeholder="权限名称" id="searchValueId" name="">
            <button type="submit" class="btn btn-success" id="searchBtnId" name=""><i class="Hui-iconfont">&#xe665;</i> 搜权限节点</button>
        </div>
    </div>
    <div class="cl pd-5 bg-1 bk-gray mt-20">
        <span class="l">
            <c:forEach items="${menus}" var="menu">
                <c:if test="${pageId==menu.menuId}">
                    <c:if test="${menu.del == 1}">
                        <a href="javascript:;" onclick="datadel()" class="btn btn-danger radius"><i class="Hui-iconfont">&#xe6e2;</i> 批量删除</a>
                    </c:if>
                    <c:if test="${menu.add == 1}">
                        <a href="javascript:;" onclick="admin_permission_add('添加菜单节点','/webpage/modules/oa/admin-permission-add.jsp','','480')" class="btn btn-primary radius"><i class="Hui-iconfont">&#xe600;</i> 添加一级菜单</a>
                     </c:if>
                </c:if>
            </c:forEach>
        </span>
        <span class="r">共有数据：<strong>54</strong> 条</span> </div>
    <table class="table table-border table-bordered table-bg table-sort">

    </table>
    <div  class="cl pd-5 bg-1 bk-gray mt-20">
        <div id="pageIds" class="col-xs-8 col-offset-6"></div>
    </div>
</div>
<!--_footer 作为公共模版分离出去-->
<%--<script type="text/javascript" src="lib/jquery/1.9.1/jquery.min.js"></script>--%>
<%--<script type="text/javascript" src="lib/layer/2.4/layer.js"></script>--%>
<%--<script type="text/javascript" src="static/h-ui/js/H-ui.min.js"></script>--%>
<%--<script type="text/javascript" src="static/h-ui.admin/js/H-ui.admin.js"></script> <!--/_footer 作为公共模版分离出去-->--%>
<%@include file="/webpage/common/include/footer.jsp"%>
<!--请在下方写此页面业务相关的脚本-->
<script type="text/javascript" src="${ctxLib}/datatables/1.10.0/jquery.dataTables.min.js"></script>

<script type="text/javascript" src="${ctxLib}/layui/layui.all.js"></script>
<link href="${ctxLib}/layui/css/layui.css" rel="stylesheet" type="text/css" />
<script type="text/javascript">
    var jsonMsg={};
    layui.config({
        base : '${ctxLib}/layui/lay/modules/'
    }).extend({
        treeTable : 'treeTable/treeTable'
    });
    layui.use(['treeTable', 'table', 'layer','laypage'],function () {
        var table = layui.table;
        var layer = layui.layer;
        var treeTable = layui.treeTable;
        var laypage = layui.laypage;

        //渲染表格
        var renderTable = function(key){
            var countTotal = 0;
            treeTable.render({
                elem: '.table-sort',
                // even:true,开启隔行背景
                tree: {
                    iconIndex: 2,  // 折叠图标显示在第几列
                    idName: 'pid',  // 自定义id字段的名称
                    pidName: 'parentId',  // 自定义标识是否还有子节点的字段名称
                    haveChildName: 'haveChild',  // 自定义标识是否还有子节点的字段名称
                    isPidData: true,  // 是否是pid形式数据
                    getIcon: function(d) {  // 自定义图标
                        // d是当前行的数据
                        if (d.haveChild) {  // 判断是否有子集
                            return '<i class="ew-tree-icon ew-tree-icon-folder"></i>';
                        } else {
                            return '<i class="ew-tree-icon ew-tree-icon-file"></i>';
                        }
                    }
                },
                cols: [
                    {type: "checkbox", width: 50},
                    {field: 'menuId', title: '序号', width: 60,templet:function (d) {
                         return ++countTotal;
                        }},
                    {field: 'menuName', title: '菜单名称',width:240, align: 'center'},
                    {field: 'url', title: 'url',align: 'center'},
                    // {field: 'permission', title: '拥有权限',align: 'center'},
                    {field: 'icon',title: '图标', templet:function (d) {
                        return '<i class="Hui-iconfont">'+d.icon+'</i>'
                        },align: 'center'},
                    {templet: complain, title: '操作', align: 'center'}
                ],
                reqData: function(data, callback) {
                    // 在这里写ajax请求，通过callback方法回调数据
                    // $.get('http://localhost:8080/sys/menu/listjson?page.pageNo='+pageNo+'&page.pageSize='+pageSize+'&menuName='+key, function (res) {
                    //     getPage(res.pageNo,res.count,res.pageSize)
                    //     callback(res.data);  // 参数是数组类型
                    // });
                    $.ajax({
                        url:'${ctxPath}${pageMenuMsg.url}alljson?menuName='+key,
                        type:'get',
                        cache:false,
                        success:function (res) {
                           callback(res);  // 参数是数组类型
                        },
                        error:function (res) {
                            
                        }
                    });
                },
                //数据渲染完的回调
                done: function () {
                    //关闭加载
                    layer.closeAll('loading');
                }
            })
        };
        function bottomMenu(d) {
            var menuAdd = "";
            var menuDel = "";
            var menuUpd = "";
            var menuStr = [];
            if($('#pageAdd').val() == 1){
                menuStr.push('<a title="添加下级菜单" href="javascript:;" onclick="admin_permission_add(\'菜单添加\',\'/webpage/modules/oa/admin-permission-add.jsp\',\'\',\'480\','+ d.pid +')" class="ml-5" style="text-decoration:none">');
                menuStr.push('<i class="Hui-iconfont">&#xe600;</i></a>');
            }
            if($('#pageUpd').val() == 1){
                menuStr.push('<a title="编辑" href="javascript:;" onclick="admin_permission_edit(\'菜单编辑\',\'/sys/menu/updmsg?id='+d.menuId+'\',\'4\',\'\',\'480\')" class="ml-5" style="text-decoration:none">');
                menuStr.push('<i class="Hui-iconfont">&#xe6df;</i></a>');
            }
            if($('#pageDel').val()== 1){
                menuStr.push('<a title="删除" href="javascript:;" onclick="admin_permission_del(this,'+"'"+d.menuId+"'"+')" class="ml-5" style="text-decoration:none">');
                menuStr.push('<i class="Hui-iconfont">&#xe6e2;</i></a>');
            }
            return menuStr;
        }

        $('#searchBtnId').click(function () {
            var key = $('#searchValueId').val();
            if(key.trim().length == 0)
                layer.alert("搜索不能为空",{icon:1});
            else
                renderTable(key);

        });

        renderTable("");
        function complain(d){//操作中显示的内容
            if(d.permissionUrl==null){
                return bottomMenu(d).join('');
                // [
                //     '<a title="添加下级菜单" href="javascript:;" onclick="admin_permission_add(\'菜单添加\',\'/webpage/modules/oa/admin-permission-add.jsp\',\'\',\'380\','+ d.pid +')" class="ml-5" style="text-decoration:none">',
                //     '<i class="Hui-iconfont">&#xe600;</i></a>',
                //     '<a title="编辑" href="javascript:;" onclick="admin_permission_edit(\'菜单编辑\',\'/sys/menu/updmsg?id='+d.menuId+'\',\'4\',\'\',\'380\')" class="ml-5" style="text-decoration:none">',
                //     '<i class="Hui-iconfont">&#xe6df;</i></a>',
                //     '<a title="删除" href="javascript:;" onclick="admin_permission_del(this,'+"'"+d.menuId+"'"+')" class="ml-5" style="text-decoration:none">',
                //     '<i class="Hui-iconfont">&#xe6e2;</i></a>',
                // ].join('');
                // '<a class="operation" lay-event="edit" href="javascript:void(0)" onclick="editDepartment(\''+ d.menuId + '\')" title="编辑">',
                //     '<i class="layui-icon layui-icon-edit"></i></a>',
                // '<a class="operation" lay-event="" href="javascript:void(0)" onclick="delDepartment(\''+ d.menuId + '\')" title="删除">',
                //     '<i class="layui-icon layui-icon-delete" ></i></a>',
            }else{
                return '';
            }

        }



    });

    // layui.use('tree', function(){
    //     layui.tree({
    //         elem:'table-sort',
    //
    //     });
    // });

    /*
        参数解释：
        title	标题
        url		请求的url
        id		需要操作的数据id
        w		弹出层宽度（缺省调默认值）
        h		弹出层高度（缺省调默认值）
    */
    /*管理员-权限-添加*/

    function admin_permission_add(title,url,w,h,pid){
        jsonMsg.pid = pid;
        layer_show(title,url,w,h);
    }
    /*管理员-权限-编辑*/
    function admin_permission_edit(title,url,id,w,h){
        layer_show(title,url,w,h);
    }

    /*管理员-权限-删除*/
    function admin_permission_del(obj,id){
        var param = {};
        param.menuId = id;
        layer.confirm('确认要删除吗？',function(index){
            $.ajax({
                type: 'GET',
                url: ' ${ctxPath}${pageMenuMsg.delUrl}',
                dataType: 'json',
                data:param,
                success: function(data){
                    $(obj).parents("tr").remove();
                    layer.msg('已删除!',{icon:1,time:1000},function () {
                        parent.location.reload();//父容器刷新
                    });
                },
                error:function(data) {
                    console.log(data.msg);
                },
            });
        });
    }
</script>
</body>
</html>